package com.dvdfe8.company.modelo.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.dvdfe8.company.modelo.Entity.AccountEntity;
import com.dvdfe8.company.modelo.generic.GenericHibernateDaoImpl;

@Repository
public class AccountDaoImpl extends GenericHibernateDaoImpl<AccountEntity, Integer> implements AccountDao {

    private static final Logger logger = Logger.getLogger(AccountDaoImpl.class);

    @Autowired
    public AccountDaoImpl(SessionFactory sessionFactory) {
        logger.info("Inyeccion SessionFactory en clase AccountDaoImpl");
        super.setSessionFactory(sessionFactory);
    }

    public AccountEntity getAccountDetails(String accountNumber) {
        logger.info("Llamando al metodo getAccountDetails con parametro accountNumber " + accountNumber);
        return (AccountEntity) getHibernateTemplate().get(AccountEntity.class, new Integer(accountNumber));

    }

    @Override
    public List<AccountEntity> findAll() throws Exception {
        logger.info("Llamando al metodo findAll");
        return getHibernateTemplate().loadAll(AccountEntity.class);
    }

    @Override
    public AccountEntity findById(Integer id) throws Exception {
        logger.info("Llamando al metodo findById con parametro id " + id.toString());
        return (AccountEntity) getHibernateTemplate().get(AccountEntity.class, id);
    }

}